<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm  */

$this->pageTitle=Yii::app()->name . ' - Login';
?>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'loginform',
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
        'htmlOptions'=>array(
            'class'=>'form-vertical',
        ),
)); ?>

<p>Enter username and password to continue.</p>

<div class="control-group" id="div-username">
    <div class="controls">
        <div class="input-prepend">
            <span class="add-on">
                <i class="icon-user"></i>
            </span>
            <?php if ($model->hasErrors('username') !== null): ?>
                <?php echo $form->textField($model,'username',array('placeholder'=>'Username','tooltiperror'=>'username')); ?>
            <?php else: ?>
                <?php echo $form->textField($model,'username',array('placeholder'=>'Username')); ?>
            <?php endif; ?>
            <?php $form->error($model,'username'); ?>
        </div>
    </div>
</div>

<div class="control-group" id="div-password">
    <div class="controls">
        <div class="input-prepend">
            <span class="add-on">
                <i class="icon-lock"></i>
            </span>
            <?php if ($model->hasErrors('password') !== null): ?>
                <?php echo $form->textField($model,'password',array('placeholder'=>'Password','tooltiperror'=>'password')); ?>
            <?php else: ?>
                <?php echo $form->textField($model,'password',array('placeholder'=>'Password')); ?>
            <?php endif; ?>
            <?php $form->error($model,'password'); ?>
        </div>
    </div>
</div>

<div class="form-actions">
    <span class="pull-left"><a href="#" class="flip-link" id="to-recover">Lost password?</a></span>
    <span class="pull-right">
        <input class="btn btn-inverse" type="button" name="yt0" value="Login">
    </span>
</div>

<?php $this->endWidget(); ?>

<script type="text/javascript">
$(document).ready(function() {
    $('[name="yt0"]').click(function() {
        window.loginform.submit();
    });
    var error_msg = "";
    <?php if ($model->hasErrors('username') !== null): ?>
        $("#div-username").addClass('error');
        error_msg += "<?php echo $model->getError('username'); ?>";
    <?php endif; ?>
    <?php if ($model->hasErrors('password') !== null): ?>
        $("#div-password").addClass('error');
        error_msg += "<?php echo $model->getError('password'); ?>";
    <?php endif; ?>
    
    if(error_msg.length > 0) alert(error_msg);
});
</script>
